Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add various hooks #676

Closed
wants to merge 10 commits into from
Closed

Add various hooks #676

wants to merge 10 commits into from

Conversation

Sunketchupm
Copy link
Contributor

After my previous PR for HOOK_HEALED_MARIO and HOOK_HURT_MARIO got closed, I took the time to add in a new hook that I'd also like to see added

This PR includes:
HOOK_HEALED_MARIO (Params: MarioState m, MarioHealType healType; Returns: None)
HOOK_HURT_MARIO (Params: MarioState m, MarioHurtType hurtType; Returns: None)
HOOK_AFTER_QUARTER_STEP (Params: MarioState m, integer stepType, integer stepResult, integer stepNumber; Returns: integer stepResult`)

I may add more hooks in the future but these are the main 3 I want in coop

@Isaac0-dev
Copy link
Contributor

Isaac0-dev commented Feb 20, 2025

can you please explain why these hooks are needed? and provide an example of something you may want to do that you can't already do with the current hooks?
adding new hooks isn't exactly cheap

@Sunketchupm
Copy link
Contributor Author

HOOK_AFTER_PHYS_STEP allows me to prevent ledgegrabs and bonks more cleanly and naturally without having to recreate the entire step system. My current use for this is to create an object that prevents bonking altogether in order to bounce Mario correctly.

HOOK_HEALED_MARIO and HOOK_HURT_MARIO can be replaced much easier and right now my main use for them is to make a custom health system. This can already be done with HOOK_BEFORE_MARIO_UPDATE and HOOK_MARIO_UPDATE I believe, however specific hooks for heals/hurt just makes sense for me for these uses.

This isn't related but I figured out why we don't have a hook that prevents objects from unloading.

@Isaac0-dev
Copy link
Contributor

just a heads up, you could already do HOOK_AFTER_PHYS_STEP like this for air steps (not tested, consider it psuedocode):

local sStep = false
hook_event(HOOK_BEFORE_PHYS_STEP, function(m, stepType, stepArgs)
    if sStep then return end
    if stepType ~= STEP_TYPE_AIR then return end
    sStep = true
    local stepResult = perform_air_step(m, stepArgs)
    sStep = false
    if stepResult == AIR_STEP_HIT_WALL then
        return AIR_STEP_NONE
    end
    return stepResult
end)

but it won't hurt to have it anyway.
the hooks for damage and healing seems a bit unnecessary to me, since they're very use case specific..
not saying they need to be removed, i'm just skeptical.

Copy link
Contributor

@Isaac0-dev Isaac0-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some changes, also please fix merge conflicts

ceilOffset = ceilHeight - (nextPos[1] + 160.0f);
if (ceilOffset < -30.0f) { stepResult = HANG_HIT_CEIL_OR_OOB; }
if (ceilOffset > 30.0f) { stepResult = HANG_LEFT_CEIL; }
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change this code? it was much more readable before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code was rewritten to be like this because all of the returns. although made the code easier to read, made it pretty incompatible with the hook.

if (m->health < 0x100) {
if (m == &gMarioStates[0]) {
// never kill remote marios
set_mario_action(m, ACT_STANDING_DEATH, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the previous way of killing mario is still needed, because they were specifically for airborne actions. it would set mario as dead, but the death action doesn't play until mario reaches the floor. setting mario's action while in the air will teleport mario to the ground even if he's not there yet.

@Sunketchupm
Copy link
Contributor Author

I don't think I'll go anywhere with this PR so I'll close it for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants